Skip to content

Improve shape handling in generate_samples #3456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 2, 2019

Conversation

lucianopaz
Copy link
Contributor

This PR fixes #3421 and #3147.

Both errors happened because of how distributions.distribution.generate_samples handled the supplied: parameter shapes, broadcast_shape and dist_shape. To make this fix more robust, I wrote a small module of shape broadcasting utilities that are now used by generate_samples and make it more robust to shape problems. I added a test suite for these functions and also for sample_prior_predictive with certain RV shapes and sample sizes that caused #3421 and #3147.

Issue #3422 remains open because that problem happens in distributions.distribution._draw_value and until it is fixed, some of the tests in the testsuite are expected to fail.

Things I would like to ask:

  • @canyon289, this is the first test suite I've written that uses pytest fixtures. Could you comment on whether the fixtures and test structures are ok or if they could be improved?
  • @ColCarroll, I think that you had written most of the original generate_samples function. Could you review the new version to see if you spot problems?

@lucianopaz
Copy link
Contributor Author

I added a really small code to use numpy.vectorize with the proper signature for theano compiled functions. Now this PR also should fix #3422.

@lucianopaz
Copy link
Contributor Author

I think this is ready for review again

@lucianopaz lucianopaz mentioned this pull request May 1, 2019
67 tasks
Copy link
Member

@ColCarroll ColCarroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple nits, and will merge after work if no one has any objections!

slicer_tail = [slice(None)] * len(sp_shape)
broadcasted_samples.append(param[tuple(slicer_head + slicer_tail)])
return np.broadcast_arrays(*broadcasted_samples)
return np.asarray(samples)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

size_tup=size_tup,
dist_shape=dist_shape,
broadcast_shape=broadcast_shape,
test=broadcast_shape[:len(size_tup)] == size_tup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like informative exceptions and am fine leaving it here, just want to flag that it is named test, so maybe you intended to remove it?

@@ -0,0 +1,369 @@
#!/usr/bin/env python3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we don't typically include shebangs (#!) in files

@ColCarroll ColCarroll merged commit f5d8324 into pymc-devs:master May 2, 2019
@ColCarroll
Copy link
Member

Thanks @lucianopaz! Looks like no one will ever have a shape problem with PyMC3 again 😀 (this is seriously good, careful, and useful work, though!)

@lucianopaz
Copy link
Contributor Author

@ColCarroll, one can always dream 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sample_prior_predictive() failing based solely on samples parameter
2 participants